﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;

namespace PPTtoPNG
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button_pptFileSelect(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                String fileName = openFileDialog.FileName;
                text_pptFilePath.Text = fileName;
            }
        }

        private void button_pptSavePath(object sender, EventArgs e)
        {
            FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                String foldName = folderBrowserDialog.SelectedPath;
                text_pptSavePath.Text = foldName;
            }
        }

        private void button_submit(object sender, EventArgs e)
        {
            String fileName = text_pptFilePath.Text;
            String foldName = text_pptSavePath.Text;
            Microsoft.Office.Interop.PowerPoint.Application pptApplication = new Microsoft.Office.Interop.PowerPoint.Application();
            Presentation pptPresentation = pptApplication.Presentations.Open(fileName, MsoTriState.msoFalse,
MsoTriState.msoFalse, MsoTriState.msoFalse);
            int index = 0;
            foreach (Microsoft.Office.Interop.PowerPoint.Slide slid in pptPresentation.Slides)
            {
                ++index;
                //设置图片大小
                slid.Export(foldName+ "\\"+ string.Format("page{0}.png", index.ToString()), "png");
            }
            //释放资源
            pptPresentation.Close();
            pptApplication.Quit();
            GC.Collect();

        }

        private void text_pptFilePath_TextChanged(object sender, EventArgs e)
        {

        }

        private void text_pptSavePath_TextChanged(object sender, EventArgs e)
        {

        }

    }
}
